package com.hfdg.authority.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfdg.prototype.base.utils.TimeUtils;
import com.hfdg.authority.mapper.AuthRoleMapper;
import com.hfdg.authority.entity.AuthRole;
import com.hfdg.authority.service.AuthRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @ClassName AuthRoleServiceImpl
 * @Description TODO
 * @Author yuelh
 * @Date 2019/1/19 18:26
 * @Version 1.0
 * @Company 会飞的锅工作室
 **/
@Service
public class AuthRoleServiceImpl implements AuthRoleService {
    @Autowired
    AuthRoleMapper authRoleMapper;

    @Override
    public String insert(AuthRole authRole) {
        String uid = UUID.randomUUID().toString();
        authRole.setUid(uid);
        authRole.setDelFlag("0");
        authRole.setCreateTime(new Date());
        authRoleMapper.insert(authRole);
        return uid;
    }

    @Override
    public Integer update(AuthRole authRole) {
        authRole.setUpdateTime(new Date());
        return authRoleMapper.update(authRole);
    }

    @Override
    public Integer  delete(String uid) {
        return authRoleMapper.delete(uid);
    }
    @Override
    public Integer batchDelete(String[] uids) {
            return authRoleMapper.batchDelete(uids);
    }

    @Override
    public AuthRole get(String uid) {
        return authRoleMapper.get(uid);
    }

    @Override
    public List<AuthRole> list(AuthRole authRole) {
    return  authRoleMapper.list(authRole);
    }

    @Override
    public PageInfo<AuthRole> getPagingData(int offset, int limit,String orderBy, AuthRole authRole) {
        if(null==orderBy|| StringUtils.isBlank(orderBy)){
        PageHelper.startPage((offset/limit)+1,limit);
        }else{
        PageHelper.startPage((offset/limit)+1,limit,orderBy);
        }
        PageInfo<AuthRole> pageInfo =new PageInfo<>(authRoleMapper.list(authRole));
            return pageInfo;
            }
    @Override
    public String insertOrUpdate(AuthRole authRole){
        if(null!=authRole.getUid()){
            this.update(authRole);
        }else{
            this.insert(authRole);
        }
        return authRole.getUid();
    }

    @Override
    public List<Map<String, Object>> listBase(AuthRole authRole) {
        return authRoleMapper.listBase(authRole);
    }
}
